<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/qt3support/text/q3syntaxhighlighter.cpp -->
<head>
  <title>Qt 4.3: Q3SyntaxHighlighter Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">Q3SyntaxHighlighter Class Reference<br /><sup><sup>[<a href="qt3support.html">Qt3Support</a> module]</sup></sup></h1>
<p>The Q3SyntaxHighlighter class is a base class for implementing <a href="q3textedit.html">Q3TextEdit</a> syntax highlighters. <a href="#details">More...</a></p>
<pre> #include &lt;Q3SyntaxHighlighter&gt;</pre><p><b>This class is part of the Qt 3 support library.</b> It is provided to keep old source code working. We strongly advise against using it in new code. See <a href="porting4.html#qsyntaxhighlighter">Porting to Qt 4</a> for more information.</p>
<ul>
<li><a href="q3syntaxhighlighter-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="q3syntaxhighlighter.html#Q3SyntaxHighlighter">Q3SyntaxHighlighter</a></b> ( Q3TextEdit * <i>textEdit</i> )</li>
<li><div class="fn"/>virtual <b><a href="q3syntaxhighlighter.html#dtor.Q3SyntaxHighlighter">~Q3SyntaxHighlighter</a></b> ()</li>
<li><div class="fn"/>int <b><a href="q3syntaxhighlighter.html#currentParagraph">currentParagraph</a></b> () const</li>
<li><div class="fn"/>virtual int <b><a href="q3syntaxhighlighter.html#highlightParagraph">highlightParagraph</a></b> ( const QString &amp; <i>text</i>, int <i>endStateOfLastPara</i> ) = 0</li>
<li><div class="fn"/>void <b><a href="q3syntaxhighlighter.html#rehighlight">rehighlight</a></b> ()</li>
<li><div class="fn"/>void <b><a href="q3syntaxhighlighter.html#setFormat">setFormat</a></b> ( int <i>start</i>, int <i>count</i>, const QFont &amp; <i>font</i>, const QColor &amp; <i>color</i> )</li>
<li><div class="fn"/>void <b><a href="q3syntaxhighlighter.html#setFormat-2">setFormat</a></b> ( int <i>start</i>, int <i>count</i>, const QColor &amp; <i>color</i> )</li>
<li><div class="fn"/>void <b><a href="q3syntaxhighlighter.html#setFormat-3">setFormat</a></b> ( int <i>start</i>, int <i>count</i>, const QFont &amp; <i>font</i> )</li>
<li><div class="fn"/>Q3TextEdit * <b><a href="q3syntaxhighlighter.html#textEdit">textEdit</a></b> () const</li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The Q3SyntaxHighlighter class is a base class for implementing <a href="q3textedit.html">Q3TextEdit</a> syntax highlighters.</p>
<p>A syntax highligher automatically highlights parts of the text in a <a href="q3textedit.html">Q3TextEdit</a>. Syntax highlighters are often used when the user is entering text in a specific format (for example, source code) and help the user to read the text and identify syntax errors.</p>
<p>To provide your own syntax highlighting for <a href="q3textedit.html">Q3TextEdit</a>, you must subclass Q3SyntaxHighlighter and reimplement <a href="q3syntaxhighlighter.html#highlightParagraph">highlightParagraph</a>().</p>
<p>When you create an instance of your Q3SyntaxHighlighter subclass, pass it the <a href="q3textedit.html">Q3TextEdit</a> that you want the syntax highlighting to be applied to. After this your <a href="q3syntaxhighlighter.html#highlightParagraph">highlightParagraph</a>() function will be called automatically whenever necessary. Use your <a href="q3syntaxhighlighter.html#highlightParagraph">highlightParagraph</a>() function to apply formatting (e.g&#x2e; setting the font and color) to the text that is passed to it.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="Q3SyntaxHighlighter"></a>Q3SyntaxHighlighter::Q3SyntaxHighlighter ( <a href="q3textedit.html">Q3TextEdit</a> * <i>textEdit</i> )</h3>
<p>Constructs the <a href="q3syntaxhighlighter.html">Q3SyntaxHighlighter</a> and installs it on <i>textEdit</i>. Ownership of the <a href="q3syntaxhighlighter.html">Q3SyntaxHighlighter</a> is transferred to the <i>textEdit</i></p>
<h3 class="fn"><a name="dtor.Q3SyntaxHighlighter"></a>Q3SyntaxHighlighter::~Q3SyntaxHighlighter ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
<p>Destructor. Uninstalls this syntax highlighter from the <a href="q3syntaxhighlighter.html#textEdit">textEdit</a>()</p>
<h3 class="fn"><a name="currentParagraph"></a>int Q3SyntaxHighlighter::currentParagraph () const</h3>
<p>Returns the id of the paragraph which is highlighted, or -1 of no paragraph is currently highlighted.</p>
<p>Usually this function is called from within <a href="q3syntaxhighlighter.html#highlightParagraph">highlightParagraph</a>().</p>
<h3 class="fn"><a name="highlightParagraph"></a>int Q3SyntaxHighlighter::highlightParagraph ( const <a href="qstring.html">QString</a> &amp; <i>text</i>, int <i>endStateOfLastPara</i> )&nbsp;&nbsp;<tt> [pure virtual]</tt></h3>
<p>This function is called when necessary by the rich text engine, i.e&#x2e; on paragraphs which have changed.</p>
<p>In your reimplementation you should parse the paragraph's <i>text</i> and call <a href="q3syntaxhighlighter.html#setFormat">setFormat</a>() as often as necessary to apply any font and color changes that you require. Your function must return a value which indicates the paragraph's end state: see below.</p>
<p>Some syntaxes can have constructs that span paragraphs. For example, a C++ syntax highlighter should be able to cope with <tt>/</tt><tt>*...*</tt><tt>/</tt> comments that span paragraphs. To deal with these cases it is necessary to know the end state of the previous paragraph (e.g&#x2e; &quot;in comment&quot;).</p>
<p>If your syntax does not have paragraph spanning constructs, simply ignore the <i>endStateOfLastPara</i> parameter and always return 0.</p>
<p>Whenever highlightParagraph() is called it is passed a value for <i>endStateOfLastPara</i>. For the very first paragraph this value is always -2. For any other paragraph the value is the value returned by the most recent highlightParagraph() call that applied to the preceding paragraph.</p>
<p>The value you return is up to you. We recommend only returning 0 (to signify that this paragraph's syntax highlighting does not affect the following paragraph), or a positive integer (to signify that this paragraph has ended in the middle of a paragraph spanning construct).</p>
<p>To find out which paragraph is highlighted, call <a href="q3syntaxhighlighter.html#currentParagraph">currentParagraph</a>().</p>
<p>For example, if you're writing a simple C++ syntax highlighter, you might designate 1 to signify &quot;in comment&quot;. For a paragraph that ended in the middle of a comment you'd return 1, and for other paragraphs you'd return 0. In your parsing code if <i>endStateOfLastPara</i> was 1, you would highlight the text as a C++ comment until you reached the closing <tt>*</tt><tt>/</tt>.</p>
<h3 class="fn"><a name="rehighlight"></a>void Q3SyntaxHighlighter::rehighlight ()</h3>
<p>Redoes the highlighting of the whole document.</p>
<h3 class="fn"><a name="setFormat"></a>void Q3SyntaxHighlighter::setFormat ( int <i>start</i>, int <i>count</i>, const <a href="qfont.html">QFont</a> &amp; <i>font</i>, const <a href="qcolor.html">QColor</a> &amp; <i>color</i> )</h3>
<p>This function is applied to the syntax highlighter's current paragraph (the text of which is passed to the <a href="q3syntaxhighlighter.html#highlightParagraph">highlightParagraph</a>() function).</p>
<p>The specified <i>font</i> and <i>color</i> are applied to the text from position <i>start</i> for <i>count</i> characters. (If <i>count</i> is 0, nothing is done.)</p>
<h3 class="fn"><a name="setFormat-2"></a>void Q3SyntaxHighlighter::setFormat ( int <i>start</i>, int <i>count</i>, const <a href="qcolor.html">QColor</a> &amp; <i>color</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<h3 class="fn"><a name="setFormat-3"></a>void Q3SyntaxHighlighter::setFormat ( int <i>start</i>, int <i>count</i>, const <a href="qfont.html">QFont</a> &amp; <i>font</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<h3 class="fn"><a name="textEdit"></a><a href="q3textedit.html">Q3TextEdit</a> * Q3SyntaxHighlighter::textEdit () const</h3>
<p>Returns the <a href="q3textedit.html">Q3TextEdit</a> on which this syntax highlighter is installed</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
